//
// Created by ningjian on 2021/9/26.
//

#include <odp/odp.h>
#include <iostream>
#include <fstream>

#include <opencv2/opencv.hpp>

using namespace std;

int main(int argc, char **argv) {

    // 加载数据
    ifstream readfile("../test/yolov3_output_1.txt");
    std::vector<float> values;
    while (!readfile.eof()) {
        std::string line;
        getline(readfile, line);
        values.push_back(std::strtof(line.c_str(), NULL));
    }
    std::cout << values.size() << std::endl;
    // 进行后处理
    odp::ODP odp_instance;
    odp_instance.SetParameter(0.5,0.7);
    odp_instance.Process_Array(values.data(), values.size(), 20);
    auto result = odp_instance.GetResult();
    std::cout << result << std::endl;

    // 显示结果
    auto img = cv::imread("../test/dog-cycle-car.png");
    cv::Mat resize_img;
    cv::resize(img, resize_img, {512, 512});
    // draw
    cv::Scalar color{255, 0, 0};
    for (int i = 0; i < result.size().height; ++i) {
        cv::rectangle(resize_img,
                      {(int) result.at<float>(i, 0),(int) result.at<float>(i, 1)},
                      {(int) result.at<float>(i, 2),(int) result.at<float>(i, 3)},
                      color,3);
    }
    cv::imshow("ObjectDetects", resize_img);
    cv::waitKey(0);


    return 0;
}